/*分页JS*/
var rsss = false;
$(function() {

	if (Number($("[name='totalCount']").val()) > 0) {
		var pages = [], totalPage = Number($("[name='totalPage']").val()), totalCount = Number($(
				"[name='totalCount']").val()), currentPage = Number($(
				"[name='pageNum']").val()) == 0 ? 1 : Number($(
				"[name='pageNum']").val());
		pages[pages.length] = ' <th colspan="100"><i>当前第' + currentPage + '页/共'
				+ totalPage + '页</i><i>共' + totalCount + '条记录</i>';

		// console.log(currentPage);
		if (currentPage == 1) {
			pages[pages.length] = ' <li ><a class="done">首页</a></li>';
		} else {
			pages[pages.length] = ' <li ><a class="first">首页</a></li>';
		}

		if (currentPage < 5) {
			for (var i = 1; i <= (totalPage > 10 ? 10 : totalPage); i++) {
				var c = "";
				if (currentPage == i) {
					c = "sel";
				}
				pages[pages.length] = '<li><a href="#" class=' + c + ' >' + i
						+ '</a></li>';

			}
		} else if (currentPage >= totalPage - 5) {
			for (var i = ((totalPage - 9) < 1 ? 1 : (totalPage - 9)); i <= totalPage; i++) {
				var c = "";
				if (currentPage == i) {
					c = "sel";
				}
				pages[pages.length] = '<li><a href="#" class=' + c + ' >' + i
						+ '</a></li>';

			}
		} else {
			for (var i = currentPage - 4; i <= currentPage + 5; i++) {
				var c = "";
				if (currentPage == i) {
					c = "sel";
				}

				pages[pages.length] = '<li><a href="#" class=' + c + ' >' + i
						+ '</a></li>';

			}
		}

		if (currentPage < totalPage) {
			pages[pages.length] = '<li ><a class="next">下一页</a></li><li ><a class="last">尾页</a></li>';
		} else {
			pages[pages.length] = '<li ><a class="done">下一页</a></li><li ><a class="done">尾页</a></li>';
		}
		// pages[pages.length] = '<input type="text" name="page"
		// value="'+currentPage+'"/>';
		// pages[pages.length] = '<input type="button" value="跳转"
		// class="btn_violet" />';
		$("#PageNum").html(pages.join("")).find(
				"a:not(.next,.prev,.first,.last,.done)").click(function() {
			$("[name='currentPage']").val($(this).text());
			$("#pagerForm").submit();
		});
		$("#PageNum").find("a.first").click(function() {
			num = 1;
			$("[name='currentPage']").val(num);
			$("#pagerForm").submit();
		});
		$("#PageNum").find("a.prev").click(
				function() {
					num = Number($("[name='currentPage']").val()) - 1 < 0 ? 0
							: Number($("[name='currentPage']").val()) - 1;
					$("[name='currentPage']").val(num);
					$("#pagerForm").submit();
				});
		$("#PageNum").find("a.next").click(
				function() {
					$("[name='currentPage']").val(
							Number($("[name='currentPage']").val()) + 1);
					$("#pagerForm").submit();
				});
		$("#PageNum").find("a.last").click(function() {
			num = Number($("[name='totalPage']").val());
			$("[name='currentPage']").val(num);
			$("#pagerForm").submit();
		});
		$("#PageNum").find("input.btn_violet").click(function() {
			num = Number($("[name='page']").val());
			if (num > totalPage) {
				num = totalPage;
			} else if (num < 1) {
				num = 1;
			}
			$("[name='currentPage']").val(num);
			$("#pagerForm").submit();
		});
	}
});
